package com.atmc;

import com.atmc.bean.Advice;
import com.atmc.bean.Authority;
import com.atmc.bean.Bill;
import com.atmc.bean.Rule;
import com.atmc.mapper.AdviceMapper;
import com.atmc.mapper.AuthorityMapper;
import com.atmc.mapper.BillMapper;
import com.atmc.service.BillService;
import com.atmc.service.RuleService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.*;
import java.util.List;

@SpringBootTest
public class MyTestApplication {
    @Autowired
    BillService billService;
    @Autowired
    RuleService ruleService;
    @Autowired
    AuthorityMapper authorityMapper;
    @Autowired
    AdviceMapper adviceMapper;

    @Test
    public void test1(){
        List<Bill> bills = billService.selectAll();
        System.err.println(bills);
    }
    @Test
    public void test2(){
        Bill bill=new Bill(null,"兰考板蓝根","年",1000,10000,"兰考医药有限公司","付款",null,null);
        int insert = billService.insertOne(bill);
        System.err.println(insert);

    }
    @Test
    public void test3(){
        Bill bill=new Bill(null,"兰考板蓝根","年",10,100,"兰考医药有限公司","未付款",null,null);
        billService.updateOne(bill);

    }
    @Test
    public void test4(){
        List<Rule> list = ruleService.selectAll();
        for (Rule rule : list) {
            System.out.println(rule
            );
        }

    }
    @Test
    public void test5(){

        List<Authority> list = authorityMapper.selectAll();
        System.out.println(list);

    }
    @Test
    public void test6(){

        Authority authority = authorityMapper.selectOne("张五");
        System.out.println(authority);

    }
    @Test
    public void test7(){
//        List<Advice> list = adviceMapper.selectAll();
//        System.out.println(list);
        Advice advice=new Advice(null,"eafgafgafgafgafga",null,null,null);
        adviceMapper.insertOne(advice);
    }
    //通过字节流 来复制文件 *.jpg .....文件
    @Test
    public void test8()  {

//        Authority authority = authorityMapper.selectOne("张五");
//        System.out.println(authority);
        FileInputStream fis= null;
        FileOutputStream fos= null;
        try {
            File read=new File("D:\\IdeaProjects\\kinggroup524\\cloud-consumer81\\src\\main\\resources\\static\\img\\email.jpg");
            File witer=new File("D:\\IdeaProjects\\kinggroup524\\cloud-consumer81\\src\\main\\resources\\static\\img\\email1.jpg");

            fis = new FileInputStream(read);
            fos = new FileOutputStream(witer);
            byte[] buff=new byte[5];
            int len;
            //每次读取的字节存放在byte数组里，
            //输出流去将buff里的字节存放在指定的文件里
            while((len = fis.read(buff)) !=-1){
                fos.write(buff,0,len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fis != null){

                    fis.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                try {
                    if (fos != null){

                        fos.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }
    }
}
